package com.dykj.fireFighting.web.app;

import com.dykj.fireFighting.api.fire.contractPayRecord.entity.ContractPayRecord;
import com.dykj.fireFighting.api.fire.contractPayRecord.service.IContractPayRecordService;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.dto.CommonDto;
import com.dykj.fireFighting.common.core.utils.UUIDUtils;
import com.dykj.fireFighting.common.core.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Slf4j
@Api(value = "app 维保合同付款记录接口", tags = {"app 维保合同付款记录接口"})
@RestController
@RequestMapping("app/contractPayRecord")
public class AppContractPayRecordController {
    @DubboReference
    private IContractPayRecordService contractPayRecordService;


    /**
     * 列表
     *
     * @return
     */

    @GetMapping("/list")
    public CommonResult treeGrid(String contractId) {
        List<ContractPayRecord> list = contractPayRecordService.getListByContractId(contractId);
        return CommonResult.success(list);
    }



    /**
     * 保存信息
     */
    @AutoLog(value = "-保存信息")
    @ApiOperation(value = "保存信息", notes = "保存信息")
    @PostMapping("/save")

    public CommonResult save(@Valid @RequestBody ContractPayRecord contractPayRecord) {
        try {
            contractPayRecord.setId(UUIDUtils.get32UUID());
            contractPayRecord.setCreateTime(new Date());
            contractPayRecordService.save(contractPayRecord);

            return CommonResult.success("添加成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }

    /**
     * 修改信息
     */
    @AutoLog(value = "-修改信息")
    @ApiOperation(value = "修改信息", notes = "修改信息")
    @PostMapping("/update")

    public CommonResult update(@Valid @RequestBody ContractPayRecord contractPayRecord) {
        try {

            contractPayRecordService.updateById(contractPayRecord);
            return CommonResult.success("修改成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }

    /**
     * 删除信息
     */
    @AutoLog(value = "-删除信息")
    @ApiOperation(value = "删除信息", notes = "删除信息")

    @PostMapping("/delete")
    public CommonResult delete(@RequestBody String[]ids) {
        try {
            contractPayRecordService.removeByIds(Arrays.asList(ids));
            return CommonResult.success("删除成功");
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResult.failed("添加失败，请联系管理员");
        }
    }
}
